let zh = document.querySelector(".zhanghao");
let mm = document.querySelector(".mima");
let li = document.querySelector(".li");
var but = document.querySelector('button');
//检测账号密码
li.onclick = function () {
    axios.get("http://jx.xuzhixiang.top/ap/api/login.php", {
        params: {
            username: zh.value,
            password: mm.value,
        },
    })
        .then((resData) => {
            //   console.log(resData);
            let data = resData.data;
            console.log(data);
            if (data.code == 0) {
                alert("登录失败，请核对账号或密码");
            } else {
                localStorage.setItem('uid',data.data.id)
                localStorage.setItem('token',data.data.token)
                location.href = "../html/index.html"
            }
        })
};
//密码框显示和隐藏
var ji = 1;
but.onclick = function () {
    if (ji == 1) {
        mm.type = 'password';
        this.innerHTML = '显'
        ji = 0;
    } else {
        mm.type = 'Text';
        this.innerHTML = '隐'
        ji = 1
    }
}
//扫码登录和账号登录切换
var shao = document.querySelectorAll('.shao')
var boxs = document.querySelectorAll('.boxs')
for (i = 0; i < shao.length; i++) {
    shao[i].setAttribute('index', i)
    shao[i].onclick = function () {
        for (i = 0; i < shao.length; i++) {
            shao[i].className = 'shao'
        }
        this.className = 'shao xian'
        var index = this.getAttribute('index')
        for (i = 0; i < boxs.length; i++) {
            boxs[i].className = 'boxs';
        }
        boxs[index].className = 'boxs look'


    }
}
//缓慢动画封装
function animate(obj, terget) {
    //先清除
    clearInterval(obj.timer);
    obj.timer = setInterval(function () {
        //移动步值
        // var step = Math.floor((terget - obj.offsetLeft) / 10);//目标值-元素距离左边父元素距离/10
        // var step = Math.ceil((terget - obj.offsetLeft) / 10);//目标值-元素距离左边父元素距离/10
        var step = (terget - obj.offsetLeft) / 10;//目标值-元素距离左边父元素距离/10
        // console.log(step);
        // step = stpe < 0 ? Math.ceil(step) : Math.floor(step)//小于0向上，大于0向下
        step = stpe > 0 ? Math.ceil(step) : Math.floor(step)//大于0向上，小于0向下
        if (obj.offsetLeft == terget) {
            //停止动画
            clearInterval(obj.timer);
        }
        obj.style.left = obj.offsetLeft + step + 'px';
    }, 10)
}
//二维码移动手机出现和隐藏
var er = document.querySelector('.er')
var qr = document.querySelector('.qr')
var shou = document.querySelector('.shou')
qr.addEventListener('mouseover', function () {
    // console.log(er.offsetLeft);
    er.style.left='10px';
    // animate(er, 10);
    console.log(er.offsetLeft);
    if (er.offsetLeft == 10) {
        shou.style.display = 'block';
    }

})
qr.addEventListener('mouseout', function () {
    // console.log(er.offsetLeft);
    er.style.left='100px';
    // animate(er, 100);  
    //   console.log(er.offsetLeft);
    if (er.offsetLeft == 100) {
        shou.style.display = 'none';
    }


})